import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import set_node_cls from "@dfeidao/atom-web/ui/set-node-cls";

import render from '@dfeidao/atom-web/render/render';
import p002 from './p002';
import p003 from './p003';
import p005 from './p005';

export default async function a004(fd: IFeidaoAiBrowserComponent, e: Event) {
	// todo
	const n = e.currentTarget as HTMLDivElement;
	const nodes = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-actions="click:a003"]');
	const ne = nodes.getAttribute('data-no');
	console.log("非风险7777=>", ne);

	// 查询风险点数据
	const pn = fd.data.params['page-no'] as string;
	let pno = 1;
	if (pn) {
		pno = parseInt(pn, 10);
	}

	console.log(pno);

	// 查询风险点名称
	const d = fd.data.node.querySelector<HTMLInputElement>('[data-name="sousuo"]');
	const v = d.value;

	console.log("buidsa", v);

	const res = await nodejs<{ res: Array<{}>; c: number }>('risk_point/zj-000001/s002', {
		risk_po_name: v,
		page_no: pno,
		risk_po_type_no: ne
	});
	console.info("差的啥=》", res);

	const p2 = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p002"]');
	const p3 = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p003"]');
	const p5 = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p005"]');
	if (res.c > 0) {
		render(fd, res.res, p002, 'p002', 'inner');
		render(fd, res.c, p003, 'p003', 'inner');

		set_node_cls(p2, 'display-n', false);
		set_node_cls(p3, 'display-n', false);
		set_node_cls(p5, 'display-n', true);
	} else {
		render(fd, '', p005, 'p005', 'inner');

		set_node_cls(p2, 'display-n', true);
		set_node_cls(p3, 'display-n', true);
		set_node_cls(p5, 'display-n', false);
	}


}
